﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

using BL.Client.BudgetReportBL;



namespace UI.BudgetReport
{
    public partial class BRUserLogin : Form
    {
        BudgetReportServerice BRS;
        
        public BRUserLogin()
        {
            InitializeComponent();
         }

        private void BRUserLogin_Load(object sender, EventArgs e)
        {
            this.BRS = new BudgetReportServerice("BudgetReport.ini");
            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(new TcpClientChannel(), false);
        }

        private void BRUserLogin_FormClosing(object sender, FormClosingEventArgs e)
        {
            foreach (IChannel ic in ChannelServices.RegisteredChannels)
            {
                ChannelServices.UnregisterChannel(ic);
            }
        }

        private void sbtnQuit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            string server_ip = cbbServerIP.Text;
            string user_name = cbbUserName.Text;
            string user_password = tbPassword.Text;
            OperateResult result = BRS.UserIndentify(server_ip, user_name, user_password);

            if (result == OperateResult.Success)
            {
                (new BRMain(this, this.BRS)).Show();
                this.Visible = false;
            }
            else if(result == OperateResult.Fail)
            {
                MessageBox.Show("用户名不存在或密码错误！");
            }
            else if(result == OperateResult.DisConnect)
            {
                MessageBox.Show("请检查网络链接");
            }
            else if(result == OperateResult.WrongInput)
            {
                MessageBox.Show("请正确填写信息！");
            }
                
        }


        
    }
}
